package multimanipulators.finders;

import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import be.djdb.UnConstruct;

import multimanipulators.interfaces.Converters;
import multimanipulators.interfaces.Finders;
/**
 * @author Lieven Roegiers
 * @copyright 2010
 * @project javamylibs
 * @from http://javamylibs.googlecode.com/svn/trunk/
**/
@UnConstruct
public class Finder_Tag_value extends F_abstractTag implements Finders {	
	public String name ="Finder";
	public boolean isstart;
	public int firstint;
	private int pos[];
	private int position;
	public boolean ismatch;
	private Converters converter;
	private int mlength;
	private Map<Integer, Integer> positions;
	//private myfinder rec;

	public void init (){
		ismatch = false;
		isstart = false;
        positions = new LinkedHashMap<Integer,Integer>();
        pos = new int[10];
	}
	public Finder_Tag_value(boolean endtag) {
		super('<', '/', '>');
		init();
	}
	public Finder_Tag_value(boolean endtag,Converters converter) {
		super('<', '/', '>');
		this.converter= converter;
		init();
	}
	public boolean ismatchfound(){
		return ismatch;
	}
	public String toString() {
		return new String("<FIND:"+first+"&then:"+last+">");
	}
	public String getTofind(){
		return new String("'"+first+"'this'"+"'"+last+"'");
	}
	public boolean isnext(int achar){
		if(ismatch){init();}
		mlength++;
			return(istag((char)achar));
	}
	private boolean istag(char achar){
		if(isstart || achar == first){	
			if(achar == last ){	
				ismatch =  true;
			}else{
				isstart = true;	
			}
			return true;
		}else{
			return false;
		}
	}
	private void getvalue(){
		
	}
	public void setConverter(Converters converter) {
		this.converter= converter;
	}
	public void convert(char[] data, OutputStreamWriter doutstream) throws Exception {
		char result[] = new char[mlength];
		try{//debug error carry return line windows
		    //System.arraycopy(input, start, result,0, mlength);
		}catch (ArrayIndexOutOfBoundsException e) {
		    //System.arraycopy(input, start, result,0, mlength-1);
		}
		converter.manipulate(data, doutstream);
	}
	@Override
	public int compareTo(Object o) {
		// TODO Auto-generated method stub
		return 0;
	}
	public int getusedbuferlength() {
		return mlength;
	}
	@Override
	public int getusedbufferlength() {
		// TODO Auto-generated method stub
		return 0;
	}
}
